#!/bin/sh
#
#######################################################################
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.  If not, write to
# the Free Software Foundation, 675 Mass Ave, Cambridge, MA 02139, USA.
#######################################################################

# This script sends packages


VERSION=`grep "AC_INIT" configure.ac | sed -e 's/.*\[\([0-9]\.[0-9]\+\)\].*/\1/'`

SEND_PACKAGE=false
SEND_WEBPAGE=false

while test -n "$1"
do
	case "$1" in
	-h*|--h*)
		echo "Usage: %0 [-opts]"
		echo "where -opts is one or more of the following:"
		echo "  --send-all      send every thing (like specifying all the --send options"
		echo "  --send-package  send the package on source forge"
		echo "  --send-webpage  send the webpage on source forge"
		exit 1
		;;
	--send-all) SEND_PACKAGE=true; SEND_WEBPAGE=true;;
	--send-package) SEND_PACKAGE=true;;
	--send-webpage) SEND_WEBPAGE=true;;
	*) echo "ERROR: unknown option \"$1\"."; exit 1;;
	esac
	shift
done

if $SEND_PACKAGE
then
	(
	cd ../packages/apple_emulator-$VERSION
	ncftpput upload.sourceforge.net incoming *
	)
fi

if $SEND_WEBPAGE
then
	(
	mkdir -p tmp
	cp -rf doc/html tmp
	d=`date -r doc/html/index.html +"%B %d, %Y"`
	set `md5sum ../packages/apple_emulator-$VERSION/apple_emulator-$VERSION-src.tar.gz`
	m=$1
	sed -e "s/<DATE>/$d/g" -e "s/<VERSION>/$VERSION/g" \
		-e "s/<MD5SUM>/$m/g" \
		doc/html/index.html >tmp/html/index.html
        cd tmp/html
	echo "<html><head><title>Apple Emulator Changes</title></head><body><pre>" >changes.html
	cat ../../doc/CHANGES.txt >>changes.html
	echo "</pre></body></html>" >>changes.html
        tar cjf ../web-page.tar.bz2 .
        cd ..
        if scp web-page.tar.bz2 alexis_wilke@apple-emulator.sourceforge.net:/home/groups/a/ap/apple-emulator/htdocs/web-page.tar.bz2 \
        && ssh alexis_wilke@apple-emulator.sourceforge.net "cd /home/groups/a/ap/apple-emulator/htdocs/; tar -mxjf web-page.tar.bz2; rm -rf web-page.tar.bz2";
        then
                rm -rf web-page.tar.bz2 html
        fi
	)
fi

